<template>
  <div class="common-page" style="height: 600px">
    <div class="title">当前申报的项目</div>
    <SearchForm
      :search-list="searchList"
      :search-params="searchParams"
      @search="onSearch"
      @reset="onReset"
    />
    <el-form>
      <el-form-item>
        <div style="text-align: right">
          <el-button type="primary" @click="onAdd">新建</el-button>
        </div>
      </el-form-item>
    </el-form>
    <div class="table-box">
      <el-table
        v-loading="loading"
        height="100%"

        :data="tableData"
        element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(255, 255, 255, 0.8)"
        @selection-change="onSelect"
      >

        <el-table-column v-for="item in columns" :key="item.prop" :prop="item.prop" :label="item.label" align="center" />
      </el-table>
    </div>
    <div class="page-box">
      <el-pagination
        background
        :current-page="pageNo"
        :page-sizes="pageSizes"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalSize"
        @size-change="changePageSize"
        @current-change="changePageNo"
      />
    </div>
  </div>
</template>

<script>
import crud from '@/mixins/crud'
import { http } from '@/api'
export default {
  name: 'Index',
  mixins: [crud],
  data() {
    return {
      request: http.project_center,
      searchList: [
        {
          key: 'projectType',
          name: 'select',
          label: '项目类型',
          options: [
            { value: '1', name: '房地产' },
            { value: '2', name: '商业项目' },
            { value: '3', name: '大型工业聚集区' },
            { value: '4', name: '大型乡村经营性公共服务设施' }
          ]
        },
        {
          key: 'investor',
          name: 'select',
          label: '组织单位',
          options: [
            { value: '1', name: '资规局' },
            { value: '2', name: '发改局' },
            { value: '3', name: '国企' }
          ]
        },
        {
          key: 'projectName',
          name: 'input',
          label: '项目名称'
        },
        {
          key: 'timeValue',
          name: 'datetime',
          valueFormat: 'yyyy-MM-dd',
          dateType: 'daterange',
          label: '时间'
        },
        {
          key: 'status',
          name: 'select',
          label: '状态',
          options: [
            { value: '0', name: '未审核' },
            { value: '1', name: '评审会议申请中' },
            { value: '2', name: '已通过' },
            { value: '3', name: '未通过' },
            { value: '4', name: '评审会议组织中' },
            { value: '5', name: '会中评审' },
            { value: '6', name: '已入库' }
          ]
        }
      ],
      searchParams: {
        projectType: '',
        investor: '',
        projectName: '',
        timeValue: [],
        status: ''
      },
      columns: [
        { prop: 'projectName', label: '项目名称' },
        { prop: 'projectTypeName', label: '项目类型' },
        { prop: 'investorName', label: '组织单位' },
        { prop: 'createTime', label: '评审申请时间' },
        { prop: 'statusName', label: '审批结果' }
      ],
      tableData: [

      ]
    }
  },
  methods: {
    formatTableData(data) {
      data.forEach(el => {
        el.projectTypeName = this.searchList[0].options.find(item => item.value == el.projectType)?.name
        el.investorName = this.searchList[1].options.find(item => item.value == el.investor)?.name
        el.statusName = this.searchList[4].options.find(item => item.value == el.status)?.name
      })
    },
    onRead(item) {
      this.$refs.detailRef.open(item)
    },
    onUpload() {},
    onPass(rowItem) {
      this.$confirm('确认通过？', '提示', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.request.updateStatus({
            id: rowItem.id
          }).then(res => {
            this.onSearch()
          })
        })
        .catch(() => {

        })
    },
    onReject(rowItem) {
      this.$confirm('确认拒绝？', '提示', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.request.updateStatus({
            id: rowItem.id

          }).then(res => {
            this.onSearch()
          })
        })
        .catch(() => {

        })
    }
  }
}
</script>

<style scoped lang="scss">
</style>
